package com.example.designPatten.observer.ObserverSingle;

import java.util.ArrayList;
import java.util.List;

import com.example.designPatten.observer.ObserverSingle.inter.Observer;
import com.example.designPatten.observer.ObserverSingle.inter.Subject;

/**
* @Title:   []
* @Description: 
* @Date : 2016年4月20日下午4:43:02
* @Company: SI-TECH
* @author : LIJXD
* @version : 1.0
* @modify history
*  <p>修改日期    修改人   修改目的<p> 	
*/
public class WeatherData implements Subject{

	private float temperature;
	private float humidity;
	private float pressure;
	private List<Object> observers;
	
	
	
	public WeatherData() {
		observers = new ArrayList<Object>();
	}


	@Override
	public void registerObserver(Observer o) {
		observers.add(o);
	}

 
	@Override
	public void removeObserver(Observer o) {
		int i = observers.indexOf(o);
		if(i>0){
			observers.remove(o);
		}
	}

 
	@Override
	public void notifyObservsers() {
		for(int i=0;i<observers.size();i++){
			Observer obj = (Observer) observers.get(i);
			obj.update(temperature, humidity, pressure);
		}
	}

	public void messurementChanges(){ //测量
		notifyObservsers();
	}
	
	public void setMessurement(float temperature,float  humidity, float pressure){
		this.temperature = temperature;
		this.humidity = humidity;
		this.pressure = pressure;
		messurementChanges();
	}
	
}
